package com.boarsoft.boar.gateway.server.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsOperations;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.demo.gateway.server.entity.PocAccountReverseRequest;
import com.boarsoft.demo.gateway.server.entity.PocAccountTransferRequest;
import com.boarsoft.demo.gateway.server.service.PocAccountTransferService;

import freemarker.template.Configuration;

@RestController
public class DemoController {

	// @Autowired
	// private JmsTemplate jms;
	@Autowired
	protected JmsOperations jms;

	@Autowired
	private Configuration config;

	@Autowired
	// @Qualifier("accountTransferServ")
	@Qualifier("demoMocker")
	private PocAccountTransferService accountTransferServ;

	@RequestMapping(value = "/message", method = RequestMethod.POST)
	public String testMessage() {
		// System.out.println("Sending an email message.");
		// jmsTemplate.convertAndSend("mailbox", new Email("info@example.com",
		// "Hello"));

		PocAccountTransferRequest transferReques = new PocAccountTransferRequest();
		transferReques.setCopcomment1(StringUtils.EMPTY);
		transferReques.setI1YZFLAG(0);
		transferReques.setI1ACFLAG(1);
		transferReques.setI1DBPSWD("267EB8569254C5B2");

		accountTransferServ.transfer(transferReques);

		PocAccountReverseRequest reverseRequest = new PocAccountReverseRequest();
		reverseRequest.setI1BKFLAG(9);

		accountTransferServ.reverse(reverseRequest);
		// try {
		// Template template = config.getTemplate("demo.ftl");
		// Map<String, Object> dataModel = new HashMap<>();
		// dataModel.put("name", "xiaofengzhang");
		// StringWriter sw = new StringWriter();
		// template.process(dataModel, sw);
		// System.out.println(sw.toString());
		// return sw.toString();
		// } catch (TemplateNotFoundException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// } catch (MalformedTemplateNameException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// } catch (ParseException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// } catch (IOException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// } catch (TemplateException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

		return "";
	}

}
